<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1;IE=edge">
    <meta name="viewport" content="user-scalable=no">
    <!-- vue2 -->
    <script src="/examples/js/vue.min.js"></script>
    <!-- 示例演示-公共样式 -->
    <link rel="stylesheet" href="/examples/css/railView.css" type="text/css" />
    <!-- 引入element-ui组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- 引入element-ui样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- RailUnit 插件 -->
    <script type="text/javascript" src="/RailUnit/RailUnit.umd.js" charset="utf-8"></script>
    <!-- RailUnit 样式 -->
    <link rel="stylesheet" href="/RailUnit/RailUnit.umd.css" type="text/css">
    <style>
        .el-form-item {
            display: flex;
        }
        .el-form-item__content {
            display: flex;
            align-items: center;
            margin-left: 0 !important;
        }
    </style>
</head>
<body>
    <div id="app">
        <div id="buttom-container">
            <el-button type="info" size="small" @click="mouseOperate">设置鼠标操作方式</el-button>
        </div>
        <el-dialog
            title="设置"
            :visible.sync="dialogVisible"
            width="380px"
        >
            <el-form 
                ref="formRef" 
                :model="formValues" 
                label-width="100px"
            >
                <el-form-item label="鼠标左键：">
                    <el-radio-group v-model="formValues.left">
                        <el-radio v-for="item in mouseOptions" :label="item.value" :key="item.value">{{item.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="鼠标中键：">
                    <el-radio-group v-model="formValues.middle">
                        <el-radio v-for="item in mouseOptions" :label="item.value" :key="item.value">{{item.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="鼠标右键：">
                    <el-radio-group v-model="formValues.right">
                        <el-radio v-for="item in mouseOptions" :label="item.value" :key="item.value">{{item.label}}</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <span slot="footer">
                <el-button @click="handleSubmit">确定</el-button>
                <el-button type="primary" @click="resetToDefault">恢复默认设置</el-button>
            </span>
        </el-dialog>
        <div id="viewer" style="width:100%;height:100%;position:relative;float:left"></div>
    </div>
    <script id="viewerStartup" type="module">
        const vm = new Vue({
            el: '#app',
            data: {
                bimViewer: null,
                formRef: null,
                dialogVisible: false,
                mouseOptions: [
                    {
                       label: '旋转' ,
                       value: 'orbit'
                    },
                    {
                       label: '平移' ,
                       value: 'pan'
                    },
                    {
                       label: '缩放' ,
                       value: 'zoom'
                    }
                ],
                formValues: {
                    left: 'orbit',
                    middle: 'zoom',
                    right: 'pan'
                }

            },
            mounted () {
                this.bimViewerFn()
            },
            methods: {
                // 初始化模型
                bimViewerFn() {
                    this.bimViewer = new MyViewer({
                        serverUrl: '/RailUnit/',
                        containerElement: document.getElementById('viewer'),
                        nodeVisible: false
                    })
                    this.bimViewer.loadModel2('jianzhu')
                },
                handleSubmit() {
                    const { left, middle, right } = this.formValues
                    console.log(`left：${left}, middle：${middle}, right：${right}`);
                    this.bimViewer.setMouseMapping({ left: left, middle: middle, right: right });
                },
                resetToDefault() {
                    this.bimViewer.setMouseMapping({left: 'orbit', middle: 'zoom', right: 'pan'});
                },
                mouseOperate() {
                    this.dialogVisible = true
                    let res = this.bimViewer.setMouseMapping({left: 'orbit', middle: 'zoom', right: 'pan'})
                    console.log(res, 'setMouseMapping');
                }
            }
         })
    </script>
</body>
</html>
